package com.foreveredu.furedusys.persist.hibernate;

import java.io.Serializable;
import java.util.List;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.foreveredu.furedusys.persist.IDao;

public abstract class HibernateAbstractDao<T, PK extends Serializable> extends
		HibernateDaoSupport implements IDao<T, PK> {

	private static final long serialVersionUID = 4883350117280530870L;
	private Class clz;

	public HibernateAbstractDao(Class clz) {
		this.clz = clz;
	}

	@Override
	public void delete(T entity) {
		this.getHibernateTemplate().delete(entity);
	}

	@Override
	public List<T> findAll() {
		return this.getHibernateTemplate().loadAll(clz);
	}

	@Override
	public T findById(PK pk) {
		return (T) this.getHibernateTemplate().load(clz, pk);
	}

	@Override
	public PK save(T entity) {
		return (PK) this.getHibernateTemplate().save(entity);
	}

	@Override
	public void saveOrUpdate(T entity) {
		this.getHibernateTemplate().saveOrUpdate(entity);
	}

	@Override
	public void update(T entity) {
		this.getHibernateTemplate().update(entity);
	}

}
